package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.api.admin.ChannelControllerApi;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道测试")
public class AdminController implements ChannelControllerApi {
    @Autowired
    AdChannelService adChannelService;
    /**
     * 根据名称分页查询频道列表
     *
     * @param dto
     * @return 数据集合
     */
    @PostMapping("/list")
    @Override
    @ApiOperation("分页查询")
    public ResponseResult<List<AdChannel>> findByNameAndPage(@RequestBody ChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }
    /**
     *
     * @param channel
     * @return 是否插入成功
     */
    @Override
    @PostMapping("/save")
    @ApiOperation("添加")
    public ResponseResult insert(@RequestBody AdChannel channel) {
        return adChannelService.insert(channel);
    }

    /**
     * 修改数据
     * @param channel
     * @return 是否修改
     */
    @PostMapping("/update")
    @Override
    @ApiOperation("修改")
    public ResponseResult update(@RequestBody AdChannel channel) {
        return adChannelService.update(channel);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    @Override
    @ApiOperation("根据ID删除")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return adChannelService.deleteById(id);
    }

    /**
     * 查询所有频道
     *
     * @return
     */
    @Override
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }
}






